package com.alibaba.citrus.ots.platform.enhance.repository.impl;

import com.alibaba.citrus.ots.platform.enhance.repository.InterfaceDataSyncConfigRepository;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.otsplatformenhance.interfacedataconfig.model.InterfaceDataConfig;
import com.epoch.app.otsplatformenhance.interfacedataconfig.service.InterfaceDataConfigService;
import com.epoch.app.otsplatformenhance.model.dto.DataCheckRequest;
import com.epoch.app.otsplatformenhance.model.dto.InterfaceDataConfigLoadListRequest;
import com.epoch.app.otsplatformenhance.model.enums.ConfigStatus;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: qianlei
 * @create: 2022/01/05 20:31
 */
@Component
public class InterfaceDataSyncConfigRepositoryImpl implements InterfaceDataSyncConfigRepository {
    @Resource
    InterfaceDataConfigService interfaceDataConfigService;
    @Override
    public List<InterfaceDataConfig> queryInterfaceDataConfigList(DataCheckRequest dataQueryRequest) {

        InterfaceDataConfigLoadListRequest request = new InterfaceDataConfigLoadListRequest();
        request.setOrderType(dataQueryRequest.getOrderType());
        request.setOrgOutCode(dataQueryRequest.getOrgOutCode());
        request.setChannelOutCode(dataQueryRequest.getChannelOutCode());
//        request.setVariable(request.getVariable());
        request.setStatus(ConfigStatus.Enable.getCode());
        request.setStart(0);
        request.setLimit(10000);
        Result<List<InterfaceDataConfig>> result = interfaceDataConfigService.loadList(request);
        if (result != null && CollectionUtils.isNotEmpty(result.getResult())){
            return result.getResult();
        }

        return new ArrayList<>();
    }
}
